#include "MenuAction.h"
#include "Config.h"
#include "AppChooser.h"
#include "BrowserBox.h"
#include "FileOps.h"
/*---------------------------------------------------------------------------*/
MenuAction::MenuAction(const QString & t, QObject *parent) : QAction(t,parent)
{
	text = t.toStdString();
	type = ACTION_NOTHING;
	setSeparator(true);
}
/*---------------------------------------------------------------------------*/
MenuAction::~MenuAction()
{

}
/*---------------------------------------------------------------------------*/
void MenuAction::set(vector<FileNode*> vfn, int typ,  string param1, string param2, string param3)
{
	type = typ;
	if(type) setSeparator(false);
	params[0] = param1;
	params[1] = param2;
	params[2] = param3;
	v_files = vfn;
}
/*---------------------------------------------------------------------------*/
void MenuAction::run()
{
	DEBUGMSG("MenuAction::run()");
	process();
}
/*---------------------------------------------------------------------------*/
void MenuAction::process()
{
	DEBUGMSG("MenuAction::process()");

	switch(type)
	{
		case ACTION_LAUNCH:
		{
			string cmd = "cd " + params[2] + "; " + params[0] + " " + params[1] + " & ";
			DEBUGMSG("system() : " << cmd);
			system(cmd.c_str());
		}
		break;
		
		case ACTION_OPENWITH:
		{
			AppChooser *chooser = new AppChooser( v_files );
			chooser->show();
		}
		break;
		
		case ACTION_OPENDIR:
		{
			flw->fillList( v_files[0] );
		}
		break;		

		case ACTION_CUT:
		{
			FileOps::cut( v_files );
		}
		break;
		
		case ACTION_COPY:
		{
			FileOps::copy( v_files );
		}
		break;	
		
		case ACTION_PASTE:
		{
			FileOps::paste( v_files[0]->getParent() );
		}
		break;	
		
		case ACTION_DELETE:
		{
			FileOps::remove( v_files );
		}
		break;				

		case ACTION_COPYHERE:
		{
			FileOps::copy( v_files );
			FileOps::paste( flw->getCurrentNode() );
		}
		break;
		
		case ACTION_MOVEHERE:
		{
			FileOps::cut( v_files );
			FileOps::paste( flw->getCurrentNode() );		
		}
		break;	
			
	}
}
/*---------------------------------------------------------------------------*/
string MenuAction::getParam(int i)
{
	return params[i];
}
/*---------------------------------------------------------------------------*/
void MenuAction::appendToParam(int i, string str)
{
	params[i] += " ";
	params[i] += str;
}
/*---------------------------------------------------------------------------*/
void MenuAction::setFLW(BrowserBox	*_flw)
{
	flw = _flw;
}
/*---------------------------------------------------------------------------*/
